<template>
  <div class="performanceAssessDetail-box content-box">
    <nav-title :title="title" :routerLink="routerLink"/>
    <div v-for="item in allInfo.detailList" class="performanceAssessDetail-list">
      <div class="label">{{item.title}}</div>
      <div class="value">{{item.value}}</div>
    </div>
    <div class="performanceAssessDetail-list" v-if="sectionType=='A'">
      <div class="label" style="fontWeight:bold;color:#000;">评估结果</div>
      <div class="value" v-if="allInfo.evaType == 'A'"><input style="width:100%;color:#000;font-size:16px;" :disabled="!edit" v-model="score" type="text" placeholder="请填写"/></div>
      <div class="value arrow" v-else="">
        <group>
          <popup-radio placeholder="请选择" :readonly="!edit" :options="allInfo.assessSelect" v-model="score" />
        </group>
      </div>
    </div>
    <div class="performanceAssessDetail-list" v-if="sectionType=='A'">
      <div class="label" style="fontWeight:bold;color:#000;">评估意见</div>
      <div class="value"><input style="width:100%;color:#000;font-size:16px;" type="text" :disabled="!edit" placeholder="请填写" maxlength="50" v-model="comments"/></div>
    </div>
    <button v-if="sectionType=='A' && edit" @click="submit">保存</button>
    <button class="return" v-else="" @click="()=>this.$router.go(-1)">返回</button>
  </div>
</template>

<script>
import {
  perassessApproveItemDetail,
  perassessApproveSaveassess
} from "../../api/api";
import { Group, PopupRadio } from "vux";
import qs from "qs";

export default {
  name: "PerformanceAssessDetail",
  components: {
    Group,
    PopupRadio
  },
  created() {
    this.cTransactionNbr = this.$route.query.cTransactionNbr;
    this.docid = this.$route.query.docid;
    this.version = this.$route.query.version;
    this.sectionId = this.$route.query.sectionId;
    this.catType = this.$route.query.catType;
    this.itemId = this.$route.query.itemId;
    this.title = this.$route.query.title;
    this.sectionType = this.$route.query.sectionType;
    this.epPhase = this.$route.query.epPhase;
    this.seqnbr = this.$route.query.seqnbr;
    if (this.$route.query.edit == false || this.$route.query.edit == 'false') {
      this.edit = false;
    } else {
      this.edit = true;
    }
    this.perassessApproveItemDetailFunc();
  },
  mounted() {},
  data() {
    return {
      routerLink: "",
      edit: "",
      allInfo: {
        assessSelect: []
      },
      title: "",
      cTransactionNbr: "",
      docid: "",
      version: "",
      sectionId: "",
      catType: "",
      itemId: "",
      score: "",
      comments: "",
      sectionType: ""
    };
  },
  methods: {
    // getData() {
    //   console.debug(this.year);
    // },
    perassessApproveItemDetailFunc() {
      this.$vux.loading.show();
      let params = {
        cTransactionNbr: this.cTransactionNbr,
        docid: this.docid,
        version: this.version,
        sectionId: this.sectionId,
        catType: this.catType,
        seqnbr: this.seqnbr,
        epPhase: this.epPhase,
        itemId: this.itemId
      };
      perassessApproveItemDetail(params)
        .then(res => {
          this.$vux.loading.hide();
          if (res && res.retCode === "000000") {
            this.allInfo = res.retData;
            this.score = res.retData.score;
            this.comments = res.retData.comments;
          } else {
            this.$vux.alert.show({
              title: "提示",
              content: res.retMsg
            });
          }
        })
        .catch(res => {
          this.$vux.loading.hide();
          this.$vux.alert.show({
            title: "警告",
            content: "网络异常，请稍后重试"
          });
        });
    },
    submit() {
      // if (!this.score) {
      //   this.$vux.alert.show({
      //     title: "提示",
      //     content: `评估结果不能为空！`
      //   });
      //   return;
      // }
      // if (!this.comments) {
      //   this.$vux.alert.show({
      //     title: "提示",
      //     content: `评估意见不能为空！`
      //   });
      //   return;
      // }
      this.$vux.loading.show();
      const params = {
        cTransactionNbr: this.cTransactionNbr,
        docid: this.docid,
        version: this.version,
        sectionId: this.sectionId,
        catType: this.catType,
        itemId: this.itemId,
        score: this.score,
        seqnbr: this.seqnbr,
        epPhase: this.epPhase,
        comments: this.comments
      };
      perassessApproveSaveassess(qs.stringify(params))
        .then(res => {
          this.$vux.loading.hide();
          if (res && res.retCode === "000000") {
            // this.$vux.alert.show({
            //   title: "成功",
            //   content: `提交成功！`,
            //   onHide: () => {
                this.$router.go(-1);
              // }
            // });
          } else {
            this.$vux.alert.show({
              title: "提示",
              content: res.retMsg
            });
          }
        })
        .catch(res => {
          this.$vux.loading.hide();
          this.$vux.alert.show({
            title: "警告",
            content: "网络异常，请稍后重试"
          });
        });
    }
  }
};
</script>

<style type="text/scss" lang="scss">
.performanceAssessDetail-box {
  padding-bottom: 50px;
  > button {
    width: 90%;
    height: 40px;
    line-height: 40px;
    border-radius: 8px;
    font-size: 18px;
    color: #fff;
    outline: none;
    margin-bottom: 50px;
    background-color: rgba(28, 170, 254, 1);
    font-weight: bold;
    box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.349019607843137);
    margin-top: 30px;
    &.return {
      background-color: #fff;
      color: #000;
      border: 1px solid #ccc;
    }
  }
  .performanceAssessDetail-list {
    display: flex;
    text-align: left;
    padding: 0 10px;
    .label,
    .value {
      padding: 10px 0;
      border-bottom: 1px solid #ccc;
    }
    .label {
      flex: 2;
      color: #999;
    }
    .value {
      flex: 3;
    }
    .arrow.value {
      .weui-cell {
        padding: 0;
      }
      .weui-cell__ft {
        position: relative;
        width: 100%;
        text-align: left;
        &::after {
          content: none;
        }
        &::before {
          content: "";
          position: absolute;
          width: 20px;
          height: 8px;
          background: url("../vacation/images/u183.png") 0 0 no-repeat;
          top: 8px;
          right: 20px;
          background-size: 20px 8px;
        }
      }
    }
  }
}
</style>
